﻿using LightingServer.TCP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace LightingServer.Start
{
    class Program
    {
        static void Main(string[] args)
        {
            StartDataBase();
            

            //ClientSocketListener.RequestHandler = new RequestAdapter();
            //ClientSocketListener.Start();

            //建立一个子线程，用于创建Socket来监听策略请求和发送。
            ThreadStart pcts = new ThreadStart(() => 
            {
                SL_SocketPortPolicyListener.Singleton.Start();
            });

            Thread policythread = new Thread(pcts);

            policythread.Start();

            //建立一个子线程，用于创建Socket来监听信息请求和发送。
            ThreadStart infots = new ThreadStart(() =>
            {
                AsynchronousSocketListener listener = new AsynchronousSocketListener(new RequestAdapter());
                listener.StartListening();
            });

            Thread infothread = new Thread(infots);

            infothread.Start();

            Console.WriteLine("服务已经启动。");
            Console.Read();
        }

        private static void StartDataBase()
        {
            string server = "127.0.0.1";
            string database = "zcdb";
            string uid = "root";
            string password = "";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
            LightingServerContext.ConnectionStrings = connectionString;
        }
    }
}
